import request from "@/utils/request";
import { defineStore } from "pinia";
import { IApiRes } from "@/types/data";
import { GoodsInfo } from "@/types/goods";

export default defineStore("goods", {
  state() {
    return {
      goodsInfo: {} as GoodsInfo,
    };
  },
  actions: {
    // 请求数据
    async getgoodsInfo(id: string) {
      const res = await request.get<IApiRes<GoodsInfo>>("goods", {
        params: {
          id,
        },
      });
      this.goodsInfo = res.data.result;
    },
    // 清除数据
    delGoodsInfo() {
      this.goodsInfo = {} as GoodsInfo;
    },
  },
});
